package com.zzti.serviceImpl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.zzti.mapper.OrderServerMapper;
import com.zzti.pojo.OrderServer;
import com.zzti.service.OrderServerService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;

@Service
public class OrderServerServiceImpl implements OrderServerService {
    @Autowired
    private OrderServerMapper orderServerMapper;

    @Override
    public Integer add(Integer visiterId, Integer waiterId, Integer number, Double price, Integer status, String address) {
        OrderServer os = new OrderServer();
        os.setVisiterId(visiterId);
        os.setNumber(number);
        os.setPrice(price);
        os.setTotal(number * price);
        os.setWaiterId(waiterId);
        Date date = new Date();
        os.setCreateTime(date);
        os.setStatus(status);
        if (address != null && address != "")
            os.setAddress(address);
        System.out.println(os.toString());
        return orderServerMapper.insert(os);
    }

    @Override
    public OrderServer findOne(Integer waiterId) {
        QueryWrapper<OrderServer> qw = new QueryWrapper<OrderServer>().eq("waiter_id", waiterId);
        qw.eq("status", 0);
        return orderServerMapper.selectOne(qw);
    }

    @Override
    public Integer update(OrderServer os) {
        QueryWrapper<OrderServer> qw = new QueryWrapper<OrderServer>().eq("waiter_id", os.getWaiterId());
        qw.eq("status", 0);
        return orderServerMapper.update(os, qw);
    }
}
